import { getInfo, setInfo } from '@/utils/storage'
import router from '@/router'

export default {
  state () {
    return {
      userInfo: getInfo()
    }
  },
  getters: {},
  mutations: {
    setUserInfo (state, userInfo) {
      setInfo(userInfo)
      state.userInfo = userInfo
    }
  },
  actions: {
    logout (context) {
      context.commit('setUserInfo', {})
      context.commit('cart/setCartList', [], { root: true })
      router.replace('/login')
    }
  },
  namespaced: true
}
